/*
 * This file is part of ksPlatform
 * 
 * Copyright (c) 2014-2015
 * 
 * This file is dual-licensed under the AGPLv3 (http://www.gnu.org/licenses/agpl-3.0.html) 
 * 
 * If you are unsure which license is appropriate for your use, please contact the sales department
 * at 97041437@qq.com.
 */
package cn.com.ksplatform.base.dao;

import java.util.List;

import org.springframework.jdbc.core.JdbcTemplate;

import cn.com.ksplatform.base.hibernate.dialect.IDialect;
import cn.com.ksplatform.base.page.PageInfoModel;
/**
 * Jdbc操作基类
 * @author Simon
 *
 */
public class BaseJdbcDAO extends JdbcTemplate implements IBaseJdbcDAO{
	public PageInfoModel queryPage(IDialect dialect,String sql,PageInfoModel pim,Object[] params){
		
		List result = null;
		int count = 0;
		String pageSql = dialect.getPageSql(sql, pim);
		String countSql = dialect.getCountSql(sql);
		if(params!=null && params.length>0){
			result = super.queryForList(pageSql,params);
			count = super.queryForObject(countSql,params,Integer.class);
		}else{
			result = super.queryForList(pageSql);
			count = super.queryForObject(countSql,Integer.class);
		}
		pim.setRows(result);
		pim.setTotal(count);
		return pim;
		
	}
	public PageInfoModel queryPage(IDialect dialect,String sql,PageInfoModel pim){
		return queryPage(dialect,sql,pim,null);
	}
}
